

import { setNodePosX, setNodePosY, setNodeScaleX } from "../../../../extensions/cocos-scaffold-3x/assets/common/Utils";
import { BaseComponent } from "../../../../extensions/cocos-scaffold-3x/assets/ui/base/BaseComponent";
import { Comp } from "../m/CompDef";
import { EHeroAttri } from "../m/GpDef";
import { GpEntity } from "./GpEntity";
import GpHero from "./GpHero";
import { _decorator, Component, Label, Node, Sprite, UITransform } from 'cc';
const { ccclass, property } = _decorator;


@ccclass
export default class GpHeroHud extends BaseComponent<GpHero> {

    @property(Label)
    lbHp: Label = null;


    @property(Sprite)
    prgBar: Sprite = null;

    @property(Node)
    hpPrg: Node = null;
    onInit(): void {

    }


    protected update(dt: number): void {
        const hp = Comp.Battle.Attri.getEntityAttriValue(this.prop.ecsEntity, EHeroAttri.hp)
        setNodePosY(this.hpPrg, this.prop.ske.node.getComponent(UITransform).height * this.prop.ske.node.scale.y*0.82)
        setNodeScaleX(this.prgBar.node,this.prop.battleInfo.curHp / hp)
        
        this.lbHp.string = this.prop.battleInfo.curHp + ""
        this.lbHp.node.active = false
        // this.node.setPosition(this.prop.node.position)
    }

}
